package com.haiyou.data.config.base;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.haiyou.common.spring.component.LifecycleableComponent;
import com.haiyou.common.spring.util.SpringUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class GameDataManager implements LifecycleableComponent{
	
	private static List<AbstractDataProvider<?, ?>> providerList = new ArrayList<>();
	
	public static GameDataManager getDefault(){
		return SpringUtil.getBean(GameDataManager.class);
	}

	public static void addProvider(AbstractDataProvider<?, ?> baseProvider){
		providerList.add(baseProvider);
		log.info("add {} to manager, size[ {} ]", baseProvider.getClass().getName(), providerList.size());		
	}
	
	public void reload() {
		long time = System.currentTimeMillis();
		for(AbstractDataProvider<?, ?> baseProvider : providerList){
			baseProvider.load();
		}
		initTemplate();
		log.info("reload used time : {}ms", System.currentTimeMillis() - time);
	}
	
	@Override
	public void init() {
		initTemplate();
	}

	@Override
	public void destory() {}

	@Override
	public int getOrder() {
		return LifecycleableComponent.service_order;
	}

	public void initTemplate(){ 
		
//		SpringUtil.getBean(TopRankGradeConfigProvider.class).ini();
	}
	
	
}
